package main

type LFByteInt struct {
	value uint64
}

func (p *LFByteInt) Value() uint64 {
	return p.value
}

func (p *LFByteInt) Set(value uint64) {
	p.value = value
}

func (p *LFByteInt) ReadFromBuf(buf []byte, size int) int {
	if size > len(buf) {
		return -1
	}

	p.value = 0
	for i := 0; i < size; i++ {
		p.value |= uint64(uint(buf[i]) << uint(8*i))
	}
	return size
}

func (p *LFByteInt) WriteToBuf() []byte {
	vb := []byte{
		byte(p.value),
		byte(p.value >> 8),
		byte(p.value >> 16),
		byte(p.value >> 24),
		byte(p.value >> 32),
		byte(p.value >> 40),
		byte(p.value >> 48),
		byte(p.value >> 56),
	}

	sz := 0
	for i := len(vb) - 1; i >= 0; i-- {
		if vb[i] != 0 {
			sz = i + 1
			break
		}
	}

	buf := make([]byte, 0)
	buf = append(buf, vb[:sz]...)
	return buf
}
